package lizhe.dummynode;

public class DeleteDuplicates {
    public static ListNode deleteDuplicates(ListNode head) {

        if (head == null || head.next == null)
            return head;

        ListNode dup = new ListNode(-1, head);
        ListNode cur = dup;

        while (cur.next != null && cur.next.next != null) {
            if (cur.next.next.val == cur.next.val) {
                int tmp = cur.next.val;
                while (cur.next != null && cur.next.val == tmp) {
                    cur.next = cur.next.next;
                }
            } else {
                cur = cur.next;
            }
        }
        return dup.next;
    }

    public static void main(String[] args) {

        ListNode head = new ListNode(1);
        ListNode list2 = new ListNode(2);
        ListNode list3 = new ListNode(3);
        ListNode list4 = new ListNode(3);
        ListNode list5 = new ListNode(4);
        ListNode list6 = new ListNode(4);
        ListNode list7 = new ListNode(5);
        head.next = list2;
        list2.next = list3;
        list3.next = list4;
        list4.next = list5;
        list5.next = list6;
        list6.next = list7;
        ListNode listNode = deleteDuplicates(head);
    }
}
